package com.flejay.dreamrecruiter.dao;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import com.flejay.dreamrecruiter.model.CurriculumVitae;
import com.flejay.dreamrecruiter.tools.ILoggingService;
import com.flejay.dreamrecruiter.tools.converter.TextFileConverterTool;

@Singleton
@Named("textCVReaderDao")
public class TextCVReaderDao implements ICVReaderDao{

	@Inject
	@Named("logService")
	private ILoggingService logService;
	
	@Override
	public List<CurriculumVitae> loadCVs(String path) {
		List<CurriculumVitae> curriculumVitaes = new ArrayList<CurriculumVitae>();
		final File folder = new File(path);
		if (folder.listFiles() != null){
			for (final File fileEntry : folder.listFiles()) {
		    	try {
					curriculumVitaes.add(TextFileConverterTool.convert(fileEntry));
				} catch (IOException e) {
					logService.info(this.getClass(), "la lecture du fichier {} a provoqu� une erreur. Fichier ignoré", fileEntry);
				}
		    }
		}
		return curriculumVitaes;
	}
}
